package com.coda.controller;

import com.coda.common.Result;
import com.coda.entity.Auth;
import com.coda.service.AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/warehouse/auth")
@Api(tags = "权限菜单相关接口")
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 查询所有权限菜单
     */
    @GetMapping("/auth-tree")
    @ApiOperation("查询所有权限菜单")
    public Result getAllAuth(){
        List<Auth> authList = authService.getauthList();
        return Result.ok(authList);
    }

    /**
     * 根据权限名称查询权限
     */
    @GetMapping("/name-check")
    @ApiOperation("根据权限名称查询权限")
    public Result getAuthByName(String authName){
        Auth authInfo = authService.getAuthByName(authName);
        return Result.ok(authInfo == null);
    }

    /**
     * 添加权限
     */
    @PostMapping("/auth-add")
    @ApiOperation("添加权限")
    public Result addAuth(@RequestBody Auth auth){
        authService.addAuth(auth);
        return Result.ok("添加成功");
    }

}
